package sort

import "sort"

type PairUintUint struct {
	Key   uint
	Value uint
}

type PairUintUintList []PairUintUint

func (p PairUintUintList) Len() int {
	return len(p)
}

func (p PairUintUintList) Less(i, j int) bool {
	return p[i].Value < p[j].Value
}

func (p PairUintUintList) Swap(i, j int) {
	temp := p[i]
	p[i] = p[j]
	p[j] = temp
}

func SortMapUintUint(src map[uint]uint) PairUintUintList {
	if src == nil || len(src) == 0 {
		return make(PairUintUintList, 0)
	}
	var (
		list = make(PairUintUintList, len(src))
		idx  int
	)
	for key, value := range src {
		list[idx] = PairUintUint{Key: key, Value: value}
		idx++
	}
	sort.Sort(list)
	return list
}
